<?php
/**************************** SERVICE INITIALIZATION BEGINS ****************************/
require_once("../../config.php");
require_once(ML_ROOT."/service-admin.php"); on_comments_edit();

$comment = isset($view_data[Protocol::COMMENT]) ? $view_data[Protocol::COMMENT] : NULL;
$user_list = isset($view_data[Protocol::USER_LIST]) ? $view_data[Protocol::USER_LIST] : NULL;
$target_list = isset($view_data[Protocol::TARGET_LIST]) ? $view_data[Protocol::TARGET_LIST] : NULL;
/***************************** SERVICE INITIALIZATION ENDS *****************************/
?>

<?php
/********************************* HTML CONTENT BEGINS *********************************/
require_once(ML_INCLUDE."/admin-header.php");
?>
	<h1>Comment Edit</h1>
	<form action="<?=url("/admin/comments-edit.php")?>" method="post" autocomplete="on">
	<table>
		<?php if (isset($comment[Protocol::ID])) :?>
		<tr>
			<td><label for="id">id</label></td>
			<td><input name="<?=Protocol::ID?>" id="id" type="id" value="<?=$comment[Protocol::ID]?>" readonly /></td>
		</tr>
		<?php endif ?>
		<tr>
			<td><label for="user_id">user_id</label></td>
			<td>
				<select name="<?=Protocol::USER_ID?>" id="user_id">
					<?php foreach ($user_list as $user) : ?>
					<?php if (isset($comment[Protocol::USER_ID]) && $comment[Protocol::USER_ID] == $user[Protocol::ID]) : ?>
					<option value="<?=$user[Protocol::ID]?>" selected="true">
					<?php else : ?>
					<option value="<?=$user[Protocol::ID]?>">
					<?php endif ?>
						<?=$user[Protocol::ID]." - ".$user[Protocol::NAME]?>
					</option>
					<?php endforeach ?>
				</select>
			</td>
		</tr>
		<tr>
			<td><label for="target_id">model_id</label></td>
			<td>
				<select name="<?=Protocol::TARGET_ID?>" id="target_id">
					<?php foreach ($target_list as $target) : ?>
					<?php if (isset($comment[Protocol::MODEL_ID]) && $comment[Protocol::MODEL_ID] == $target[Protocol::ID]) : ?>
					<option value="<?=$target[Protocol::ID]?>" selected="true">
					<?php else : ?>
					<option value="<?=$target[Protocol::ID]?>">
					<?php endif ?>
						<?=$target[Protocol::ID]?>
					</option>
					<?php endforeach ?>
				</select>
			</td>
		</tr>
		<tr>
			<td><label for="comment">comment</label></td>
			<?php if (isset($comment[Protocol::COMMENT])) :?>
			<td>
				<input name="<?=Protocol::COMMENT?>"
					id="comment" type="text" value="<?=$comment[Protocol::COMMENT]?>" />
			</td>
			<?php else :?>
			<td><input name="<?=Protocol::COMMENT?>" id="comment" type="text" /></td>
			<?php endif ?>
		</tr>
		<?php if (isset($comment[Protocol::LIKES])) :?>
		<tr>
			<td><label for="likes">likes</label></td>
			<td><input name="<?=Protocol::LIKES?>" id="likes" type="number" value="<?=$comment[Protocol::LIKES]?>" /></td>
		</tr>
		<?php endif ?>
		<tr>
			<td colspan="2"><button type="submit">Confirm</button></td>
		</tr>
	</table>
	</form>
<?php
require_once(ML_INCLUDE."/admin-footer.php");
/********************************** HTML CONTENT ENDS **********************************/
?>